#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <unordered_set>
using namespace std;
unordered_set<unsigned long long> memo;
int prime[10] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29};

int winner(int *hh, int n, int array[][8])
{
    unsigned long long num = 0ULL;
    for (int i = 0; i < n; i += 2)
    {
        num |= ((unsigned long long)(prime[hh[i]] * prime[hh[i + 1]])) << (4 * i);
    }
    if (memo.count(num))
        return -1;
    memo.insert(num);
    vector<int> com;
    for (int i = 0; i < n; ++i)
    {
        com.push_back(hh[i]);
    }
    for (int i = n; i > 1; i /= 2)
    {
        for (int j = 0; j < (i / 2); j++)
        {
            int u = com[j * 2], v = com[j * 2 + 1];
            com[j] = (array[u][v] == 1) ? u : v;
        }
    }
    return com[0];
}

int main()
{
    int hh[8] = {0, 1, 2, 3, 4, 5, 6, 7};
    int _array[8][8];
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            int num;
            cin >> num;
            _array[i][j] = num;
        }
    }
    int ans = 0;
    do
    {
        ans += (winner(hh, n, _array) == 0);
    } while (next_permutation(hh, hh + n));
    cout << ans << endl;
    return 0;
}